package com.woniuxy.project.campus.account.mapper;

import com.woniuxy.project.campus.account.dto.RoleNameByPemissionName;
import com.woniuxy.project.campus.account.dto.SelectPermissionByRoleIdDto;
import com.woniuxy.project.campus.account.model.Permission;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 吴彦祖
 * @since 2025年02月17日
 */
@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {

     List<Permission> selectPermissionByUserId(@Param("id") Integer id,@Param("parentId") Integer parentId);

     List<Permission> queryTheSecondaryMenu(@Param("id") Integer id,@Param("parentId") Integer parentId);

     @Select("SELECT \n" +
             "    r.name AS roleName,\n" +
             "    r.id AS roleId,\n" +
             "    rp.permission_id AS permissionId,\n" +
             "    p.permission_name AS permissionName,\n" +
             "\t\tp.parent_id as parentId\n" +
             "FROM \n" +
             "    role r\n" +
             "JOIN \n" +
             "    role_permission rp ON r.id = rp.role_id\n" +
             "JOIN \n" +
             "    permission p ON rp.permission_id = p.id;")
    List<RoleNameByPemissionName> selectPermissionByRoleId();
}
